﻿namespace DelegateDemo
{
    delegate void ShowMsg(string msg);//无返回值，带一个参数的委托
    internal class Program
    {
        delegate int Calculate(int a, int b);//返回类型是int,带两个参数的委托
        delegate void ExecuteAct();//无返回值无参数的委托
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            DelegateTest dt = new DelegateTest();

            //第一种 实名委托
            CalculateDouble Add = new CalculateDouble(dt.Add);
            Console.WriteLine(Add(2, 3));

            //第二种 匿名委托
            Calculate calculate = delegate (int a, int b)
            {
                return a * b;
            };
            Console.WriteLine(calculate(2, 3));

            //第三种 lambda表达式
            ShowMsg showMsg = (msg) =>
            {
                Console.WriteLine(msg);
            };
            showMsg("Hello, Delegate!");


            Console.ReadKey();
        }
    }
}
